﻿////////////////////////////////////////////////////////////////////////////////////////////
// File: Randomizer.cs                                                                    //
// Author: Mike Binnix                                                                    //
// Desc: This is a wrapper for the C# Random class.  This class provides enahnced         //
//       functionality for using the random number generator as a pseudo-random number    //
//       generator.  This class also includes functionality for creating random colors.   //
////////////////////////////////////////////////////////////////////////////////////////////

using System;
using Microsoft.Xna.Framework.Graphics;

namespace SlothEngine.Core
{
    public class Randomizer
    {
        #region Properties
        private Random rand;    // The random number generator
        private int seed;       // The seed value used to create pseudo-random numbers

        public int Seed
        {
            get
            {
                return seed;
            }
        }
        #endregion

        #region Constructors
        /// <summary>
        /// Default constructor.  Creates a new number generator with a random seed value.
        /// </summary>
        public Randomizer()
        {
            // Generate a random seed value
            rand = new Random();
            seed = rand.Next();

            rand = new Random(seed);

            Log.PrintLine("----------------------------------");
            Log.PrintLine("Creating new number generator.");
            Log.PrintLine("Seed = " + seed + ".");
            Log.PrintLine("----------------------------------");
        }

        /// <summary>
        /// Creates a new number generator using hte given seed value.
        /// </summary>
        /// <param name="randSeed">Seed value for number generator.</param>
        public Randomizer(int randSeed)
        {
            rand = new Random(randSeed);
            seed = randSeed;

            Log.PrintLine("----------------------------------");
            Log.PrintLine("Creating new number generator.");
            Log.PrintLine("Seed = " + seed + ".");
            Log.PrintLine("----------------------------------");
        }
        #endregion

        #region Methods
        /// <summary>
        /// Returns a random number between 0 - 2,147,483,648.
        /// </summary>
        /// <returns>Random number.</returns>
        public int NextInt()
        {
            return rand.Next();
        }

        /// <summary>
        /// Returns a random number between min - max.
        /// </summary>
        /// <param name="min">Min value that can be returned.</param>
        /// <param name="max">Max value that can be returned.</param>
        /// <returns></returns>
        public int NextInt(int min, int max)
        {
            return rand.Next(min, max);
        }

        /// <summary>
        /// Returns a random value between 0.0 - 1.0.
        /// </summary>
        /// <returns>Random number.</returns>
        public double NextDouble()
        {
            return rand.NextDouble();
        }

        /// <summary>
        /// Returns a random color.
        /// </summary>
        /// <returns>Color value.</returns>
        public Color NextColor()
        {
            byte[] temp = new byte[3];

            rand.NextBytes(temp);

            return new Color(temp[0], temp[1], temp[2]);
        }


        #endregion
    }
}
